﻿using IOSendInterface;

namespace PipeClient.Model
{
        /// <summary>
        /// 数据包
        /// </summary>
        internal class DataPage
        {
                /// <summary>
                /// 链接超时时间
                /// </summary>
                public int ConTimeOut;


                /// <summary>
                /// 数据的长度
                /// </summary>
                public int DataLen;

                /// <summary>
                /// 数据包的类型
                /// </summary>
                public Enum.PageType PageType;


                /// <summary>
                /// 数据类型（1 字符串类型 , 2 实体对象 3 字节流）
                /// </summary>
                public SendType DataType;

                /// <summary>
                /// 数据内容
                /// </summary>
                public byte[] Content;

                /// <summary>
                /// 数据包的唯一标示
                /// </summary>
                public int DataId;
                /// <summary>
                /// 包的类型(用户自定义)
                /// </summary>
                public char[] Type;
                public byte TypeLen;
                public byte HeadType;
                public int GetPageSize ()
                {
                        if (this.DataLen == 0)
                        {
                                return this.TypeLen + PipeTools.HeadLen + 1;
                        }
                        else if (this.DataLen <= short.MaxValue)
                        {
                                this.HeadType = 2;
                                return this.TypeLen + 3 + PipeTools.HeadLen + this.DataLen;
                        }
                        else
                        {
                                this.HeadType = 4;
                                return this.TypeLen + 5 + PipeTools.HeadLen + this.DataLen;
                        }
                }
        }
}
